from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status
from django import http

"""1. 一级视图, APIView 之request """
class BookAPIView(APIView):
    def get(self,request):
        """
        View:
            request.GET

        APIView:
            request.query_params
        """

        # 1.使用APIView里面的request,获取查询参数
        print(request.query_params)
        print(request.query_params.get("name"))  # 获取单个数据
        print(request.query_params.getlist("name"))  # 获取所有数据(一键多值)

        return http.HttpResponse("BookAPIView...get")


    def post(self,request):
        """
        View:
            表单: reqeust.POST
            非表单: request.body

        APIView:
            表单,非表单: request.data
        """

        #1,表单数据,非表单数据
        print(request.data)
        print(request.data.get("btitle"))

        return http.HttpResponse("BookAPIView...post")

"""2. 一级视图, APIView 之response """
class Book2APIView(APIView):
    def get(self, request):
        return Response("哈哈", status=status.HTTP_200_OK)